import * as THREE from "three";
import axios from "axios";
import LightWall from "../class/LightWall";
export const SevenExp = {
	methods:{
        async sevenExp(){
            this.loading = true;
            this.$parent.btnIsDis = true;

            // this.removeOldModel();
            this.getMapData("worldMap") ;
            await   this.loadCountryNumber(7);
            var picArr = [
                {imgUrl:"img/relatedPhoto/Seven/Montenegro1.jpg",imgDesc:"在布鲁塞尔北约总部举行的外交部长会议-北大西洋理事会与黑山的会议。"},
                {imgUrl:"img/relatedPhoto/Seven/Montenegro2.jpg",imgDesc:"在布鲁塞尔北约总部举行的北约国防部长会议-北约副秘书长与黑山国防部长的双边会晤，从左到右:Milica Pejanovic Durisic(黑山国防部长)和Rose Gottemoeller(北约副秘书长)。"},
                {imgUrl:"img/relatedPhoto/Seven/Montenegro3.jpg",imgDesc:"意大利和希腊开始对黑山实施空中警务，在模拟拦截演习中，希腊F-16D飞鹰拦截了一架黑山里尔45。黑山加入联盟一年后，北约开始在该国进行空中警务，该国没有自己的战斗机。"}
            ]
            this.changePicTexture(picArr);


            var flagAnimation = [];
            var fontAnimation;
            var arrowAnimation;
            var newCameraPos,newTargetPos ;
            var hungaryFontAnimation,bulgariaFontAnimation,romaniaFontAnimation,serbiaFontAnimation ;
            var Group  = new THREE.Group();
            Group.name = "Jb"

            var resource = new THREE.Group();
            this.scene.add(Group)


            // 字体动画
            let BalkanAnimation,EuropeAnitaion,AsiaAnimation,AfricaAnimation ;
            this.lightWall = new LightWall({x:45.45431668571693,y:5,z:-10},10,8,20,"#efca6d");
            this.lightWall.group.name = "lightWall" ;
            resource.add(this.lightWall.group) ;
            // 加载资源


            // 塞尔维亚
            let serbiaModel = this.gltfLoadModel("model/public/font/Serbia/scene.gltf") ;
            serbiaModel.then((res)=>{
                let font = res.scene ;
                serbiaFontAnimation = res.animations[0] ;
                font.name = "Serbia" ;
                resource.add(font) ;
            })

            // 国家字体模型
            let hungaryModel = this.gltfLoadModel("model/public/font/Hungary/scene.gltf") ;
            await hungaryModel.then((res)=>{
                let font = res.scene ;
                hungaryFontAnimation = res.animations[0] ;
                font.name = "Hungary" ;
                resource.add(font) ;
            })

            let bulgariaModel = this.gltfLoadModel("model/public/font/Bulgaria/scene.gltf") ;
            await bulgariaModel.then((res)=>{
                let font = res.scene ;
                bulgariaFontAnimation = res.animations[0] ;
                font.name = "Bulgaria" ;
                resource.add(font) ;
            })

            let romaniaModel = this.gltfLoadModel("model/public/font/Romania/scene.gltf") ;
            await romaniaModel.then((res)=>{
                let font = res.scene ;
                romaniaFontAnimation = res.animations[0] ;
                font.name = "Romania" ;
                resource.add(font) ;
            })

            // 欧洲字体加载
            let EuropeModel = this.gltfLoadModel("model/public/font/Europe/seene.gltf")
            await EuropeModel.then((res)=>{
                let Europe = res.scene ;
                EuropeAnitaion = res.animations[0] ;
                Europe.name = "Europe" ;
                resource.add(Europe)
            })

            // 箭头
            let widthArrowModel = this.gltfLoadModel("model/public/width_exp_arrow/scene.gltf") ;
            await widthArrowModel.then((res)=>{
                res.scene.scale.set(15,15,15) ;
                let asiaArrow = res.scene.clone() ;
                asiaArrow.name = "asiaArrow" ;
                resource.add(asiaArrow)

                let africaArrow = res.scene.clone() ;
                africaArrow.name = "africaArrow" ;
                resource.add(africaArrow)

                let europeArrow = res.scene.clone() ;
                europeArrow.name = "europeArrow" ;
                resource.add(europeArrow)

                arrowAnimation = res.animations[0] ;
            })


            let AsiaModel = this.gltfLoadModel("model/public/font/Asia/seene.gltf")
            await  AsiaModel.then((res)=>{
                AsiaAnimation = res.animations[0] ;
                let Asia = res.scene ;
                Asia.name = "Asia" ;
                resource.add(Asia)
            })

            let AfricaModel = this.gltfLoadModel("model/public/font/Africa/seene.gltf")
            await  AfricaModel.then((res)=>{
                AfricaAnimation = res.animations[0] ;
                let Africa = res.scene ;
                Africa.name = "Africa" ;
                resource.add(Africa)
            })

            let BalkanModel = this.gltfLoadModel("model/public/font/Balkan/seene.gltf")
            await BalkanModel.then((res)=>{
                BalkanAnimation = res.animations[0] ;
                let Balkan = res.scene ;
                Balkan.scale.set(0.7,0.7,0.7);
                Balkan.name = "Balkan" ;
                resource.add(Balkan)
            })



            let MontenegroLabel 	   = this.get3dLabel("黑山",false,"20px") ;
            var flagMontenegroModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
            var flagMontenegroTexture = this.changeTexture("img/flag/Montenegro.png") ;
            await flagMontenegroModel.then((res)=>{
                let flag = res.scene.clone();
                flagAnimation = res.animations[0];
                flag.name = "Montenegro";
                flag.scale.set(4, 4, 4)
                flag.children[0].children[1].material.map = flagMontenegroTexture;
                flag.children[0].children[1].material.map.needsUpdate = true;
                flag.add(MontenegroLabel)
                resource.add(flag)
            })

            let russiaLabel 	   = this.get3dLabel("俄罗斯",false,"20px") ;
            var flagRussiaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
            var flagRussiaTexture = this.changeTexture("img/flag/Russia.png") ;
            await flagRussiaModel.then((res)=>{
                let flag = res.scene.clone();
                flagAnimation = res.animations[0];
                flag.name = "Russia";
                flag.scale.set(4, 4, 4)
                flag.children[0].children[1].material.map = flagRussiaTexture;
                flag.children[0].children[1].material.map.needsUpdate = true;
                flag.add(russiaLabel)
                resource.add(flag)
            })

            var sevenExpFont = this.gltfLoadModel("model/date/7-20170605/scene.gltf")
            await sevenExpFont.then((res) => {
                let font  =  res.scene ;
                font.scale.set(10, 10, 10) ;
                fontAnimation = res.animations[0] ;
                font.name="20170605"
                resource.add(font)
            })

            this.loading = false;
            //////////////////////脚本//////////////////////
            this.seventhPromptText()
            this.$refs.Lines.src = "music/lines/seventhexp/7-0.mp3" ;
            this.$refs.Lines.play();

            newCameraPos = {
                x:19.289265626058043,
                y:67.5192378667019,
                z:131.19290633195996
            }
            newTargetPos = {
                x:29.96183114603885,
                y:0,
                z:-9.969454734593498
            }



            this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)

            setTimeout(()=>{
                let font = resource.getObjectByName("20170605");
                font.position.set(29.96183114603885,20,-9.969454734593498) ;
                this.onceActionPlay(fontAnimation,font)
                Group.add(font)
            },1500)

            setTimeout(()=>{
                let flag = resource.getObjectByName("Montenegro");
                flag.position.set(29.96183114603885,9,-9.969454734593498);
                this.onceActionPlay(flagAnimation,flag)
                Group.add(flag)
            },2000)

            setTimeout(()=>{
                let ruFlag = resource.getObjectByName("Russia");
                ruFlag.position.set(56.747633596820606,9,-35.34143761530109)
                Group.add(ruFlag)
                this.onceActionPlay(flagAnimation,ruFlag)
                this.colorMap("Russia",this.myColor.wtoArea)
            },3500)



            setTimeout(()=>{
                let font = Group.getObjectByName("20170605");
                var newPos = font.position.clone() ;
                newPos.y = -30 ;
                this.recedingModel(font,font.position,newPos,2000) ;
            },6000)

            setTimeout(()=>{
                let Balkan = resource.getObjectByName("Balkan");
                this.initBalKanLand() ;
                let lightWall = resource.getObjectByName("lightWall") ;
                Group.add(lightWall) ;
                Group.add(Balkan) ;
                Balkan.position.set(42.45431668571693,30,-14) ;
                this.onceActionPlay(BalkanAnimation,Balkan) ;
            },7100)

            setTimeout(()=>{
                newCameraPos = { x:69.80603132486631,y:274.19536272866,z:205.11496358997232} ;
                newTargetPos = { x:70.36901293087799,y:4,z:6.518457668329491} ;
                this.animateCamera(this.camera.position,this.controls.target,newCameraPos,newTargetPos,2000) ;

                let Europe = resource.getObjectByName("Europe");
                Europe.rotateX(-(Math.PI * 0.5))
                Europe.scale.set(2,2,2) ;
                Group.add(Europe) ;
                Europe.position.set(0,10,-25) ;
                this.onceActionPlay(EuropeAnitaion,Europe) ;

                // Arrow
                let arrow = resource.getObjectByName("europeArrow") ;
                arrow.rotateY(Math.PI * 0.25) ;
                arrow.position.set(5,1,-40)
                Group.add(arrow)
                this.onceActionPlay(arrowAnimation,arrow) ;

            },10100)

            setTimeout(()=>{
                let Asia = resource.getObjectByName("Asia") ;
                // Arrow
                let arrow = resource.getObjectByName("asiaArrow") ;
                arrow.rotateY(-Math.PI * 0.6) ;
                arrow.position.set(97.52444458261374,1,5.603582991887523) ;
                Group.add(arrow)
                this.onceActionPlay(arrowAnimation,arrow)

                // Font
                Asia.scale.set(2,2,2) ;
                Asia.rotateX(-(Math.PI * 0.5)) ;
                Group.add(Asia) ;
                Asia.position.set(97.52444458261374,10,5.603582991887523) ;
                this.onceActionPlay(AsiaAnimation,Asia) ;
            },11000)

            setTimeout(()=>{
                let Africa = resource.getObjectByName("Africa");
                Africa.scale.set(2,2,2) ;
                Africa.rotateX(-(Math.PI * 0.5))
                Group.add(Africa) ;

                // Arrow
                let arrow = resource.getObjectByName("africaArrow") ;
                arrow.rotateY(-Math.PI * 1.1) ;
                arrow.position.set(29.849787057140503,1,40.884134202806806)
                this.onceActionPlay(arrowAnimation,arrow)
                Group.add(arrow)

                Africa.position.set(29.849787057140503,10,37.884134202806806) ;
                this.onceActionPlay(AfricaAnimation,Africa) ;
            },11200)

            setTimeout(()=>{
                newCameraPos = {x:51.0305195506236,y:69.17741076405292,z:35.64198375967148} ;
                newTargetPos = {x:39.2502139167224,y:4,z:-14.480520584870332}

                let font = resource.getObjectByName("Serbia") ;
                font.scale.set(0.2,0.2,0.2) ;
                font.position.set(33.61152151210911,4,-12.123671726535063) ;
                font.rotateY(-Math.PI * 0.3)
                Group.add(font) ;
                this.onceActionPlay(serbiaFontAnimation,font) ;
                this.colorMap("Serbia",this.myColor.wtoArea);
                this.animateCamera(this.camera.position,this.controls.target,newCameraPos,newTargetPos,2000)
            },16000)

            setTimeout(()=>{
                let font = resource.getObjectByName("Romania") ;
                font.scale.set(0.2,0.2,0.2) ;
                font.position.set(39.284060301344795,4,-15.651359328344485) ;
                Group.add(font) ;
                this.onceActionPlay(romaniaFontAnimation,font) ;

                this.colorMap("Romania",this.myColor.natoArea) ;
            },19000)

            setTimeout(()=>{
                let font = resource.getObjectByName("Bulgaria") ;
                font.scale.set(0.2,0.2,0.2) ;
                font.position.set(39.65745799878182,4,-9.461371683883604) ;
                Group.add(font) ;
                this.onceActionPlay(bulgariaFontAnimation,font) ;
                this.colorMap("Bulgaria",this.myColor.natoArea) ;
            },20000)

            setTimeout(()=>{
                let font = resource.getObjectByName("Hungary") ;
                font.scale.set(0.2,0.2,0.2) ;
                font.position.set(31.48295785275093,4,-18.041411614197543) ;
                Group.add(font) ;
                this.onceActionPlay(hungaryFontAnimation,font)

                this.colorMap("Hungary",this.myColor.natoArea) ;
            },21000)

            setTimeout(()=>{
                this.colorMap("Montenegro",this.myColor.natoArea) ;
            },22000)


        },
        initBalKanLand(){
            var BalKanAraay = ["Kosovo","Serbia","Montenegro","Bosnia and Herz.","Croatia","Bulgaria","Romania","Albania","Macedonia","Greece","Turkey"]
            BalKanAraay.forEach((cName) => {
                this.map.children.forEach((item) => {
                    if (item.properties.name == cName) {
                        item.children.forEach((area) => {
                            if (area.type == "Mesh") {
                                area.material.color.set(this.myColor.focusArea)
                            }
                        })
                    }
                })
            })

        }
    }
}